import qs from 'qs'    

export default $axios => ({
    getNameList() {
        return $axios.get('/server/talk', {
            params: {
                type:'name',
                username:''
            }
        })
    },
    getTalkList(username){
        return $axios.get('/server/talk',{
            params:{
                type:'talk',
                username
            }
        })
    },
    insertSentence(username,admin,content){
        let time = new Date()
        let month = time.getMonth()+1
        month = month < 10 ? `0${month}` : month
        let day = time.getDay()
        day = day < 10 ? `0${day}` :day
        let hour = time.getHours()
        hour = hour <10? `0${hour}`:hour
        let minute = time.getMinutes()
        minute = minute <10? `0${minute}`:minute
        let second = time.getSeconds()
        second = second <10? `0${second}`:second
        return $axios.post('/server/talk',qs.stringify({
            username,
            admin,
            content,
            time: `${time.getFullYear()}-${month}-${day} ${hour}:${minute}:${second}`
        }))
    }
})